package rmi;

import java.rmi.*;
import java.rmi.registry.LocateRegistry;

public class Server {
    
	OficinaVtaInterfaz odvRemoto;
	CasaCentralInterfaz cprRemoto;
	
	public Server() {
	//	ServerRun.server = this;
	}
	
    public void iniciar() {
    	try {
    		System.out.println( "Iniciando servidor." );
    		LocateRegistry.createRegistry(1099);
    		
    		odvRemoto = new OficinaVtaRemote();
            Naming.rebind ("//localhost/OdvRemoto", odvRemoto);
            
            cprRemoto = new CasaCentralRemote();
            Naming.rebind ("//localhost/CprRemoto", cprRemoto);
            
            System.out.println( "Servidor activo y con objeto remoto a la espera de llamadas." );
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public static void getVinculos(){
    	try{
    		String[] vinculos = Naming.list( "" );
    		System.out.println( "Vinculos disponibles: ");
      	  	for ( int i = 0; i < vinculos.length; i++ )
      		  System.out.println( vinculos[i] );
        }
        catch (Exception e) {
        	e.printStackTrace();
        }
    }
    
    public void cerrar() {
		try {
			Naming.unbind("//localhost/OdvRemoto");
			Naming.unbind("//localhost/cprRemoto");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
    }
    
}
